#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from PIL import Image

def cover(im1, im2, d=10):
    w1, h1 = im1.size
    w2, h2 = im2.size

    if w1 != w2:
        im2 = im2.resize((w1, h2))

    im = Image.new('RGB', (w1, h1+d))   # 建立框架

    box2 = (0, h1+d-h2, w1, h1+d)  # 图片2贴到框架底部
    im.paste(im2, box2)

    box1 = (0, 0, w1, h1)         # 图片1贴到框架顶部
    im.paste(im1, box1)
    return im

# im1 = Image.open('images/1.jpg')
# im2 = Image.open('images/2.jpg')
# im3 = cover(im1, im2, d=100)
# im3.show()

images = [Image.open('images/%d.jpg' % k) for k in range(1,6)]

im0 = images[0]
for im in images[1:]:
    im0 = cover(im0, im, d=100)
im0.show()
im0.save('test.jpg')
